﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

//将一维数组转变成二维数组
//https://leetcode.cn/problems/convert-1d-array-into-2d-array/description/
class Solution {
public:
    vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
        int sz = original.size();
        if((m*n) != sz) return vector<vector<int>>();
        vector<vector<int>> vv(m,vector<int>(n));

        int pos = 0;
        for(int i = 0;i<m;++i)
            for(int k = 0;k<n;++k)
                vv[i][k] = original[pos++];

        return vv;
    }
};

//用栈操作构建数组
//https://leetcode.cn/problems/build-an-array-with-stack-operations/description/
class Solution {
public:
    vector<string> buildArray(vector<int>& target, int n) { 
        int sz = target.back();
        vector<string> vs;
        int pos = 0;
        for(int i = 1;i<=sz;++i)
        {
            vs.push_back("Push");
            if(i == target[pos])
                ++pos;
            else
                vs.push_back("Pop");
        }
        return vs;
    }
};